<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta HTTP-EQUIV="pragma" CONTENT="no-cache">
    <meta HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
    <meta HTTP-EQUIV="expires" CONTENT="0">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>添加用户</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/font-awesome.css" rel="stylesheet">
    <link href="css/animate.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet">
    <link href="css/ui.css" rel="stylesheet">
    <link href="css/layui.css" rel="stylesheet">
    <link href="css/control.css" rel="stylesheet">
    <style>
        #body {
            width: 100%;
            max-height: 100%;
            overflow-y: scroll;
            overflow-x: hidden;
        }

        .articleImg {
            /* width: 100%; */
            /* height: auto !important; */
            max-width: 100px;
        }

        th,
        td {
            text-align: center;
        }
        .textAreaBlock {
            margin-left: 130px;
            min-height: 36px;
        }
        .form_item_align_left {
            text-align: left;
        }
        .from_item_align_center {
            text-align: center;
        }

    </style>
</head>

<body class="gray-bg animated fadeInRight">
    <div id="body">
        <div class="wrapper wrapper-content">
            <div class="row">
                <div class="col-sm-12">
                    <div class="ibox float-e-margins">
                        <div class="ibox-content">

                            <div id="content">

                                <fieldset style="margin-top: 20px">
                                    <legend>添加用户</legend>
                                </fieldset>

                                <form class="form-horizontal m-t" id="commentForm">
                                    <div class="layui-form-item form_item_align_left">
                                        <div class="layui-inline input_own_readonly">
                                            <label class="layui-form-label ">登录名</label>
                                            <div class="layui-input-inline">
                                                <input id="userName" name="userName" placeholder="请输入英文" lay-verify="required|number" type="text" autocomplete="off" onblur="value = value.replace(/[^\a-\z\A-\Z0-9]/g,'')" class="layui-input" aria-required="true">
                                            </div>
                                        </div>
                                        <div class="layui-inline">
                                            <label class="layui-form-label">姓名</label>
                                            <div class="layui-input-inline">
                                                <input id="realName" name="realName" autocomplete="off" class="layui-input" aria-required="true">
                                            </div>
                                        </div>
                                        <div class="layui-inline">
                                            <label class="layui-form-label">手机号</label>
                                            <div class="layui-input-inline">
                                                <input id="mobile" name="mobile" autocomplete="off" class="layui-input">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="layui-form-item form_item_align_left">
                                        <div class="layui-inline">
                                            <label class="layui-form-label">邮箱</label>
                                            <div class="layui-input-inline">
                                                <input id="email" name="email" autocomplete="off" class="layui-input">
                                            </div>
                                        </div>
                                        <div class="layui-inline">
                                            <label class="layui-form-label">密码</label>
                                            <div class="layui-input-inline">
                                                <input type="text" id="password" name="password" placeholder="设置密码" lay-verify="required|number" autocomplete="off" class="layui-input" aria-required="true">
                                            </div>
                                        </div>
                                        <div class="layui-inline">
                                            <label class="layui-form-label">确认密码</label>
                                            <div class="layui-input-inline">
                                                <input type="text" id="surePassword" name="surePassword" placeholder="再输入一遍" lay-verify="required|number" autocomplete="off" class="layui-input" aria-required="true">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="layui-form-item form_item_align_left input_own_readonly">

                                    </div>
                                    <div class="layui-form-item form_item_align_left">
                                        <div class="layui-inline layui-form">
                                            <label class="layui-form-label">状态</label>
                                            <div class="layui-input-inline ">
                                                <select id="accountStatus">
                                                    <option value="0" >正常</option>
                                                    <option value="1" >禁用</option>
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                </form>

                            </div>
                            <div class="from_item_align_center">
                                <button class="btn btn-info layui-btn-normal uptAccount" style="margin-left: 20px">添&nbsp;&nbsp;&nbsp;&nbsp;加</button>
                                <button class="btn btn-warning layui-btn-warm cancle" style="margin-left: 30px">取&nbsp;&nbsp;&nbsp;&nbsp;消</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- 全局js -->
    <script src="js/jquery.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script src="js/work/common.js"></script>
    <!--<script src="js/plugins/laydate/laydate.js"></script>-->
    <script src="js/plugins/layer/layer.min.js"></script>
    <script src="js/plugins/layer/layer.js"></script>
    <script src="js/layui.js"></script>
    <!-- 自定义js -->
    <script src="js/content.js"></script>
    <script>

        layui.use(['form'], function(){});
        var userId = getStorage("userId");
        $(document).ready(function () {

            // 修改信息
            $('.uptAccount').click(function () {
                validateInfo();
            });
            // 取消操作
            $('.cancle').click(function () {
                window.location.href = "usermanage.html";
            });

        });

        function validateInfo() {
            var userName = $("#userName").val();
            var realName = $("#realName").val();
            var mobile = $("#mobile").val();
            var email = $("#email").val();
            var status = $("#accountStatus").val();
            var password = $("#password").val();
            var surePassword = $("#surePassword").val();
            if (isNULL(userName)) {
                layer.msg("登录名不能为空");
                return;
            }
            if (isNULL(realName)) {
                layer.msg("姓名不能为空");
                return;
            }
            if (isNULL(password)) {
                layer.msg("密码不能为空");
                return;
            }
            if (password != surePassword) {
                layer.msg("两次密码不一致");
                return;
            }
            var data = {
                userName:userName,
                realName:realName,
                mobile:mobile,
                email:email,
                password:password,
                accountStatus:status
            };
            addAccountInfo(data);
        }
        
        function addAccountInfo(data) {

            var userName = $("#realName").val();
            var realName = $("#realName").val();
            var mobile = $("#mobile").val();
            var email = $("#email").val();
            var status = $("#accountStatus").val();

            ajax({
                url: "/userm/addAccountInfo",
                type: "POST",
                dataType: "json",
                xhrFields: {
                    withCredentials: true
                },
                crossDomain: true,
                contentType: "application/json;charset=utf-8",
                data: JSON.stringify(data),
                error: function (xhr, type) {
                    layer.msg("服务器异常，请稍后重试！", {time:2000})
                },
                successx: function (data) {
                    console.log(data);
                    if (data.success == true) {
                        layer.msg('操作成功', {shift: -1,time:1500}, function() {
                            window.location.href = "usermanage.html";
                        });
                    } else {
                        layer.msg(data.message,{time:1000})
                    }
                }
            });
        }
    </script>
</body>

</html>